using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using C4F.DevKit.Contacts;
using C4F.DevKit.Contacts.Controls;

namespace C4F.DevKit.Contacts.Samples.Win
{
	public partial class ContactDetailDisplay : Form
	{
		#region Constructors

		public ContactDetailDisplay()
			: this(string.Empty)
		{			
		}

		public ContactDetailDisplay(string contactID)
		{
			InitializeComponent();
			
			this.contactDetails1.ContactsService = this.contactsService1;
			this.contactDetails1.Mode = contactID == string.Empty ? ContactDetails.EditMode.Add : ContactDetails.EditMode.Update;
			
			if(!DesignMode)
				this.contactDetails1.SetContactID(contactID);

			this.contactDetails1.ContactSaved += new ContactDetails.ContactSavedEventHandler(contactDetails1_ContactSaved);
			this.contactDetails1.ContactSaveCanceled += new ContactDetails.ContactSaveCanceledEventHandler(contactDetails1_ContactSaveCanceled);
		}

		#endregion Constructors

		#region Methods 

		#region Event Handlers

		private void contactDetails1_ContactSaveCanceled(object sender, EventArgs e)
		{
			OnContactSaveCanceled();			
		}

		private void contactDetails1_ContactSaved(object sender, C4F.DevKit.Contacts.Controls.ContactSavedEventArgs e)
		{
			OnContactSaved();			
		}

        private void ContactDetailDisplay_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                Close();
        }

		#endregion Event Handlers	
		
		#region Private

		private void OnContactSaveCanceled()
		{
			Close();
		}

		private void OnContactSaved()
		{
			Close();
		}

		#endregion Private
        
		#endregion Methods
	}
}